package qq.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telecom.Call;
import android.util.Log;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.google.android.material.textfield.TextInputLayout;

import butterknife.BindView;
import butterknife.OnClick;
import cn.imu.appdevexperiment2022.R;
import cn.imu.appdevexperiment2022.start.BaseActivity;
import qq.retrofit.bean.EditResultBean;
import qq.retrofit.bean.EditSendBean;
import qq.util.ToastUtil;


public class EditInfoActivity extends BaseActivity {
   private static final String TAG = "EditInfoActivity";
   @BindView(R.id.tv_title)
   TextView tvtitle;
   @BindView(R.id.editinfo_til_nickname)
   TextInputLayout nickname;
   @BindView(R.id.editinfo_til_phone)
   TextInputLayout phone;
   @BindView(R.id.editinfo_til_email)
   TextInputLayout email;
   @BindView(R.id.editinfo_til_classid)
   TextInputLayout classid;
   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_editinfo);
      initView();
   }
   private void initView() {
      tvtitle.setText("修改信息");
   }

   @OnClick(R.id.btn_editinfo)
   public void btn_editinfo(){

      EditSendBean editSendBean = new EditSendBean();
      editSendBean.setEmail(email.getEditText().getText().toString());
      editSendBean.setNickName(nickname.getEditText().getText().toString());
      editSendBean.setClassesId(classid.getEditText().getText().toString());
      editSendBean.setPhonenumber(phone.getEditText().getText().toString());
      editSendBean.setUpdateBy("cch");
      SharedPreferences sharedPreferences =getSharedPreferences("cch", Context.MODE_PRIVATE);

      editSendBean.setUserId(sharedPreferences.getString("userId",""));
      editSendBean.setUserName(sharedPreferences.getString("username",""));

      Call<EditResultBean> call = ApiClient.getInstance(getApplicationContext())
              .getReturnData(AuthUtil.GetAuth(),editSendBean);

      call.enqueue(new Callback<EditResultBean>() {
         @Override
         public void onResponse(Call<EditResultBean> call, Response<EditResultBean> response) {
            if (response.body()!=null){
               if (response.body().getCode()==200){
                  Log.e(TAG,response.body().getMsg().toString());
                  ToastUtil.ShowToast(getApplicationContext(),"修改成功");
                  finish();
               }else {
                  ToastUtil.ShowToast(getApplicationContext(),response.body().getMsg().toString());
               }
            }else{
               ToastUtil.ShowToast(getApplicationContext(),"网络请求错误");
            }
         }

         @Override
         public void onFailure(Call<EditResultBean> call, Throwable t) {

         }
      });
   }
}
